<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>async和await的实质</title>
  <style>
    *,
    *::after,
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    :root {
      min-height: 100vh;
    }

    :root:focus-within {
      scroll-behavior: smooth;
    }

    body {
      min-height: inherit;
    }
  </style>
</head>

<body>
  <div></div>
</body>
<script>
  "use strict"; {
    async function f() {
      console.log(0);
      // await 1 相当于 Promise.resolve(1).then(res => {});
      let res = await 1;
      console.log(res);
    };
    // f();

    // 此时的f函数相当于 f1 函数了
    function f1() {
      console.log(0);
      // 遇到 promise 就会把内容放到 微队列 任务中
      return Promise.resolve(1).then(res => {
        console.log(res);
      });
    };
    f1();

    console.log(2);
  };
</script>

</html>